<?php
/**
 * @subpackage Components
 * @link http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
 * @license    GNU/GPL
*/
 
// no direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.view');
jimport( 'joomla.application.application' );

/**
 * HTML View class for the HelloWorld Component
 *
 * @package    HelloWorld
 */
 
class HizkuntzakViewMsgs extends JView
{
    function display($tpl = null)
    {
        $greeting = "Hello Create!";
        $this->assignRef( 'greeting', $greeting );
 
        parent::display($tpl);
    }
    
	function noAccess($tpl = null)
    {
        $model = &$this->getModel();
    	
    	$rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
 		
		$msg = $rsc->no_access;
        $this->assignRef('msg',$msg);
        
        $showlink = 0;
        $this->assignRef('showlink',$showlink);
		
        parent::display($tpl);
    }
    
    function addWordsLang()
    {
    	
    	$this->addCSS();
		$this->addJavascripts();
		
    	$model = &$this->getModel();
    	
    	$rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
		$showlink = 0;
    	//Add word in db via model
        if($model->addWordsLang()){
        	$msg = $rsc->info_ok;
        	$showlink = 1;
        }
        else
        	$msg = $rsc->info_fail;
        	
        $this->assignRef('msg',$msg);
		
        $this->assignRef('showlink',$showlink);
        
		parent::display($tpl);
    }
    
	function addQasLang()
    {
    	
    	$this->addCSS();
		$this->addJavascripts();
		
    	$model = &$this->getModel();
    	
    	$rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
		$showlink = 0;
    	//Add word in db via model
        if($model->addQasLang()){
        	$msg = $rsc->info_ok;
        	$showlink = 1;
        }
        else
        	$msg = $rsc->info_fail;
        	
        $this->assignRef('msg',$msg);
		$this->assignRef('showlink',$showlink);
		
		parent::display($tpl);
    }
    
	function addNumbersLang()
    {
    	
    	$this->addCSS();
		$this->addJavascripts();
		
    	$model = &$this->getModel();
    	
    	$rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
		$showlink=0;
    	//Add word in db via model
        if($model->addNumbersLang()){
        	$msg = $rsc->info_ok;
        	$sholink=1;
        }
        else
        	$msg = $rsc->info_fail;
        	
        $this->assignRef('msg',$msg);
		$this->assignRef('showlink',$showlink);
		
		parent::display($tpl);
    }
    
	function addSongLang()
    {
    	
    	$this->addCSS();
		$this->addJavascripts();
		
    	$model = &$this->getModel();
    	
    	$rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
		$showlink=0;
    	//Add word in db via model
        if($model->addSong()){
        	$msg = $rsc->info_ok;
        	$showlink=1;
        }
        else
        	$msg = $rsc->info_fail;
        	
        $this->assignRef('msg',$msg);
		$this->assignRef('showlink',$showlink);
		
		parent::display($tpl);
    }
    
    function addWord($tpl = null)
    {
    	$this->addCSS();
		$this->addJavascripts();
		
    	$model = &$this->getModel();
    	
    	$rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
		$showlink=0;
    	//Add word in db via model
        if($model->addWord()){
        	$msg = $rsc->word_ok;
        	$showlink=1;
        }
        else
        	$msg = $rsc->word_fail;
        	
        $this->assignRef('msg',$msg);
        $this->assignRef('showlink',$showlink);
		
		parent::display($tpl);
    }
    
	function addQa($tpl = null)
    {
    	$this->addCSS();
		$this->addJavascripts();
		
    	$model = &$this->getModel();
    	
    	$rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
		$showlink=0;
    	//Add qa in db via model
        if($model->addQa()){
        	$msg = $rsc->info_ok;
        	$showlink=1;
        }
        else
        	$msg = $rsc->info_fail;
        	
        $this->assignRef('msg',$msg);
        $this->assignRef('showlink',$showlink);
		
		parent::display($tpl);
    }
    
	function addLang($tpl = null)
    {
    	$this->addCSS();
		$this->addJavascripts();
		
    	$model = &$this->getModel();

    	$rsc = $model->selectLangRsc();
		$this->assignRef('rsc',$rsc);
		
    	//Add lang in db via model
    	$result = $model->addLang();
		$showlink=0;
		
        if($result != 0 || $result != false || $result != null){
        	$msg = $rsc->lang_ok;
        	
        	$this->assignRef('lang_code', $result);
        	$showlink=1;
        	/*$url = "index.php?option=".JRequest::getCmd('option')."&task=createWordsLang&lang=".$result;
        
			JApplication::redirect( $url, $msg='', $msgType='message', true);
			*/
        }
        else{
        	$msg = $rsc->lang_fail;
        	$this->assignRef('msg',$msg);
        	
        }
		
        $this->assignRef('msg',$msg);
        $this->assignRef('showlink',$showlink);
        
		parent::display($tpl);
        
    }
    
	private function addCSS(){
			$option=JRequest::getCmd('option');
			
			$document=&JFactory::getDocument();
			
			$document->addStyleSheet('components/'.$option.'/css/smoothness/jquery-ui-1.8.15.custom.css');
	}
	
	private function addJavascripts(){
			$option=JRequest::getCmd('option');
			
			$document=&JFactory::getDocument();
			$document->addScript('components/'.$option.'/js/jquery-1.6.2.min.js');
			$document->addScript('components/'.$option.'/js/jquery-ui-1.8.15.custom.min.js');
			
			$document->addScript('components/'.$option.'/js/hizkuntzakMain.js');

	}
}